/*
 *  (c) 2010-2012 Ashwin Rayaprolu (http://linkwithweb.com)
 *
 *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
 *  file except in compliance with the License. You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software distributed under the
 *  License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 *  either express or implied. See the License for the specific language governing permissions
 *  and limitations under the License.
 */
 

SwiftUI.UIDesignContainer = function(designContainerId,options) {
  this.initialize(designContainerId,options);
};

SwiftUI.UIDesignContainer.prototype = {
/**
 * @class Implements drag-n-drop manager -- a group of linked draggables and drop zones
 * @constructs
 */
   initialize: function(designContainerId,options) {
	  this.id = designContainerId;
	  
	  // to track number of elements being dropped on to the container..
	  this.dropCounter = 0;
	  /**
	   * To track all components present on the container..
	   */
	  this.componentIds = [];
	  
      this.designComponentArray = [][];

      
      this.options{  
    	  noOfColumns : 2,
          /**
           * Can be FLOW_LAYOUT OR TABLE_LAYOUT 
           */
    	  layoutType : "TABLE_LAYOUT",
      };
      
      SwiftUI.extend(this.options, options || {});
      
      /**
       * Set Width and Height of design container
       */
      setWidth();
      setHeight();
      /**
       * Now enable drop on the container
       */
      enableDropArea();
   },
   
   
   /**
    * Makes the container dropable for Design components
    */
   enableDropArea : function(){
       //Make element droppable
       $(this.id).droppable({
			drop: function(ev, ui) {
				if (ui.helper.attr('id').search(/drag[0-999]/) != -1){
					this.dropCounter++;
					
					// Clone the element dragged to add new element to designer
					var element=$(ui.draggable).clone();
					
					element.addClass("tempclass");
					
					$(this).append(element);
					
					// Add id to element 
					element.attr("id","clonediv"+this.dropCounter);
					
					//Get the dynamically item id
					draggedNumber = ui.helper.attr('id').search(/drag([0-9])/)
					//itemDragged = "dragged" + RegExp.$1
					////console.log(itemDragged)
					element.addClass("dragged");
					// Now enable drag on the element.
					var draggedElementType = element.attr("componentType");
					
					
					enableDrag("parent","#clonediv"+counter,"true");
				}
			}
       });
   },
   
   /**
    * Set Width and Height of 
    */
   
   
};

SwiftUI.includeLoaded('SwiftUIDesignContainer.js');